package com.nageoffer.jobtrain.projects.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import com.nageoffer.jobtrain.projects.annotation.NoUserBlockingAction;
import com.nageoffer.jobtrain.projects.dto.req.UserContestCancelEnrollReqDTO;
import com.nageoffer.jobtrain.projects.dto.req.UserContestEnrollReqDTO;
import com.nageoffer.jobtrain.projects.dto.resp.UserContestRespDTO;
import com.nageoffer.jobtrain.projects.service.UserContestService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户报名竞赛控制层
 * author：唐晨
 */
@RestController
@RequiredArgsConstructor
public class UserContestController {
    private final UserContestService userContestService;

    /**
     * 用户报名竞赛功能
     */
    @NoUserBlockingAction(message = "用户状态已拉黑，禁止报名参加竞赛，请先联系管理员！")
    @PostMapping("/api/job-train/project/contest/enroll")
    public Result<Void> createEnrollContest(@RequestBody UserContestEnrollReqDTO requestParam) {
        userContestService.createRemindContest(requestParam);
        return Results.success();
    }

    /**
     * 用户取消报名竞赛功能
     */
    @PostMapping("/api/job-train/project/contest/cancel-enroll")
    public Result<Void> cancelEnrollContest(@RequestBody UserContestCancelEnrollReqDTO requestParam) {
        userContestService.cancelEnrollContest(requestParam);
        return Results.success();
    }

    /**
     * 获取用户报名竞赛列表
     */
    @PostMapping("/api/job-train/project/contest/list-enroll")
    public Result<List<UserContestRespDTO>> listEnrollContest() {
        return Results.success(userContestService.listEnrollContest());
    }

    /**
     * 获取用户报名竞赛列表 -分页查询
     */
    @GetMapping("/api/job-train/project/contest/page-list-enroll")
    public Result<IPage<UserContestRespDTO>> pageListEnrollContest(@RequestParam("current") Integer current, @RequestParam("size") Integer size) {
        return Results.success(userContestService.pageListEnrollContest(current, size));
    }

    /**
     * 用户提交竞赛完成功能
     */
    @PostMapping("/api/job-train/project/contest/finish")
    public Result<Void> finishContest(@RequestParam("contest_id") Long contestId) {
        userContestService.finishContest(contestId);
        return Results.success();
    }
}
